var hcageinf_male_3rd = [
    [0, 12.39670875],
    [0.5, 13.09058124],
    [1.5, 14.08711874],
    [2.5, 14.78693613],
    [3.5, 15.31474854],
    [4.5, 15.73100574],
    [5.5, 16.06946687],
    [6.5, 16.35083323],
    [7.5, 16.58867346],
    [8.5, 16.79234242],
    [9.5, 16.96854672],
    [10.5, 17.12224953],
    [11.5, 17.25722063],
    [12.5, 17.37638647],
    [13.5, 17.48206141],
    [14.5, 17.5761052],
    [15.5, 17.66003319],
    [16.5, 17.73509529],
    [17.5, 17.80233366],
    [18.5, 17.86262565],
    [19.5, 17.91671628],
    [20.5, 17.96524312],
    [21.5, 18.0087557],
    [22.5, 18.04773066],
    [23.5, 18.082584],
    [24.5, 18.1136802],
    [25.5, 18.14134142],
    [26.5, 18.16585223],
    [27.5, 18.18746606],
    [28.5, 18.20640918],
    [29.5, 18.22288436],
    [30.5, 18.23707397],
    [31.5, 18.24914252],
    [32.5, 18.2592389],
    [33.5, 18.26749822],
    [34.5, 18.27404343],
    [35.5, 18.27898666],
    [36, 18.28088993]

];
var hcageinf_male_5th = [
    [0, 12.65701906],
    [0.5, 13.32044646],
    [1.5, 14.27728174],
    [2.5, 14.95260171],
    [3.5, 15.46415421],
    [4.5, 15.8691643],
    [5.5, 16.19967122],
    [6.5, 16.47536935],
    [7.5, 16.70919811],
    [8.5, 16.91009725],
    [9.5, 17.08448901],
    [10.5, 17.23713485],
    [11.5, 17.3716574],
    [12.5, 17.4908732],
    [13.5, 17.59701275],
    [14.5, 17.69187059],
    [15.5, 17.77691054],
    [16.5, 17.8533412],
    [17.5, 17.92217113],
    [18.5, 17.98425002],
    [19.5, 18.04029989],
    [20.5, 18.09093897],
    [21.5, 18.13670035],
    [22.5, 18.17804666],
    [23.5, 18.21538171],
    [24.5, 18.24905963],
    [25.5, 18.27939314],
    [26.5, 18.30665884],
    [27.5, 18.33110297],
    [28.5, 18.3529454],
    [29.5, 18.37238322],
    [30.5, 18.38959366],
    [31.5, 18.40473663],
    [32.5, 18.41795686],
    [33.5, 18.42938565],
    [34.5, 18.4391425],
    [35.5, 18.44733641],
    [36, 18.45087875]

];

var hcageinf_male_10th = [
    [0, 13.02516251],
    [0.5, 13.65060862],
    [1.5, 14.55660961],
    [2.5, 15.19971068],
    [3.5, 15.68946833],
    [4.5, 16.07919601],
    [5.5, 16.3987906],
    [6.5, 16.66666311],
    [7.5, 16.89493482],
    [8.5, 17.09199625],
    [9.5, 17.26388749],
    [10.5, 17.41509522],
    [11.5, 17.54903923],
    [12.5, 17.66838282],
    [13.5, 17.7752384],
    [14.5, 17.87130795],
    [15.5, 17.95798157],
    [16.5, 18.03640827],
    [17.5, 18.10754791],
    [18.5, 18.17220989],
    [19.5, 18.23108253],
    [20.5, 18.28475566],
    [21.5, 18.33373818],
    [22.5, 18.37847196],
    [23.5, 18.41934285],
    [24.5, 18.45668966],
    [25.5, 18.49081112],
    [26.5, 18.52197209],
    [27.5, 18.55040818],
    [28.5, 18.57632988],
    [29.5, 18.59992589],
    [30.5, 18.62136598],
    [31.5, 18.64080333],
    [32.5, 18.65837661],
    [33.5, 18.67421167],
    [34.5, 18.68842306],
    [35.5, 18.70111528],
    [36, 18.70692188]

];

var hcageinf_male_25th = [
    [0, 13.57068372],
    [0.5, 14.14956186],
    [1.5, 14.99165222],
    [2.5, 15.59306745],
    [3.5, 16.05399625],
    [4.5, 16.42317173],
    [5.5, 16.72791798],
    [6.5, 16.98506483],
    [7.5, 17.20569995],
    [8.5, 17.39750375],
    [9.5, 17.56601118],
    [10.5, 17.71533838],
    [11.5, 17.84862648],
    [12.5, 17.96832482],
    [13.5, 18.07637847],
    [14.5, 18.17435644],
    [15.5, 18.26354172],
    [16.5, 18.34499597],
    [17.5, 18.41960697],
    [18.5, 18.48812414],
    [19.5, 18.55118537],
    [20.5, 18.6093378],
    [21.5, 18.66305394],
    [22.5, 18.71274439],
    [23.5, 18.75876797],
    [24.5, 18.80144034],
    [25.5, 18.84103945],
    [26.5, 18.87781252],
    [27.5, 18.91197939],
    [28.5, 18.94373671],
    [29.5, 18.97326091],
    [30.5, 19.00071086],
    [31.5, 19.02623007],
    [32.5, 19.04994856],
    [33.5, 19.07198447],
    [34.5, 19.0924454],
    [35.5, 19.11142965],
    [36, 19.12039643]

];

var hcageinf_male_50th = [
    [0, 14.09987704],
    [0.5, 14.64316166],
    [1.5, 15.43600412],
    [2.5, 16.00486374],
    [3.5, 16.44298903],
    [4.5, 16.79574194],
    [5.5, 17.08854754],
    [6.5, 17.3370563],
    [7.5, 17.55157212],
    [8.5, 17.73922696],
    [9.5, 17.90515754],
    [10.5, 18.05318182],
    [11.5, 18.18621229],
    [12.5, 18.30651948],
    [13.5, 18.41590634],
    [14.5, 18.51582732],
    [15.5, 18.60747198],
    [16.5, 18.69182501],
    [17.5, 18.76971027],
    [18.5, 18.84182358],
    [19.5, 18.90875772],
    [20.5, 18.97102152],
    [21.5, 19.02905484],
    [22.5, 19.08324035],
    [23.5, 19.13391279],
    [24.5, 19.18136713],
    [25.5, 19.22586325],
    [26.5, 19.2676328],
    [27.5, 19.30688201],
    [28.5, 19.34379561],
    [29.5, 19.37853963],
    [30.5, 19.41126382],
    [31.5, 19.44210364],
    [32.5, 19.47118205],
    [33.5, 19.49861092],
    [34.5, 19.52449237],
    [35.5, 19.54891982],
    [36, 19.56061533]

];

var hcageinf_male_75th = [
    [0, 14.56861494],
    [0.5, 15.08711634],
    [1.5, 15.84641308],
    [2.5, 16.39358344],
    [3.5, 16.81676086],
    [4.5, 17.15890008],
    [5.5, 17.44410785],
    [6.5, 17.68723352],
    [7.5, 17.89805513],
    [8.5, 18.0833399],
    [9.5, 18.24795973],
    [10.5, 18.39553386],
    [11.5, 18.52882166],
    [12.5, 18.64997322],
    [13.5, 18.76069513],
    [14.5, 18.86236381],
    [15.5, 18.95610489],
    [16.5, 19.04285027],
    [17.5, 19.12337983],
    [18.5, 19.19835262],
    [19.5, 19.26833042],
    [20.5, 19.33379585],
    [21.5, 19.39516654],
    [22.5, 19.45280617],
    [23.5, 19.50703327],
    [24.5, 19.55812882],
    [25.5, 19.60634084],
    [26.5, 19.65189056],
    [27.5, 19.69497529],
    [28.5, 19.73577202],
    [29.5, 19.77444002],
    [30.5, 19.81112317],
    [31.5, 19.84595182],
    [32.5, 19.87904443],
    [33.5, 19.91050896],
    [34.5, 19.94044406],
    [35.5, 19.9689401],
    [36, 19.98267468]

];

var hcageinf_male_90th = [
    [0, 14.95032075],
    [0.5, 15.45271898],
    [1.5, 16.1913672],
    [2.5, 16.72613306],
    [3.5, 17.14135422],
    [4.5, 17.47824383],
    [5.5, 17.75998729],
    [6.5, 18.00089735],
    [7.5, 18.2104149],
    [8.5, 18.39508504],
    [9.5, 18.55962552],
    [10.5, 18.70754506],
    [11.5, 18.84152133],
    [12.5, 18.96364248],
    [13.5, 19.07556727],
    [14.5, 19.17863446],
    [15.5, 19.27393967],
    [16.5, 19.36239056],
    [17.5, 19.44474726],
    [18.5, 19.52165255],
    [19.5, 19.59365468],
    [20.5, 19.66122498],
    [21.5, 19.72477155],
    [22.5, 19.78464999],
    [23.5, 19.84117199],
    [24.5, 19.89461234],
    [25.5, 19.94521427],
    [26.5, 19.99319434],
    [27.5, 20.03874597],
    [28.5, 20.0820427],
    [29.5, 20.12324078],
    [30.5, 20.16248136],
    [31.5, 20.19989236],
    [32.5, 20.23559005],
    [33.5, 20.26968043],
    [34.5, 20.30226036],
    [35.5, 20.3334186],
    [36, 20.34849031]

];

var hcageinf_male_95th = [
    [0, 15.16368535],
    [0.5, 15.65851855],
    [1.5, 16.38812466],
    [2.5, 16.91807663],
    [3.5, 17.33065682],
    [4.5, 17.66614058],
    [5.5, 17.94722475],
    [6.5, 18.18794607],
    [7.5, 18.3975797],
    [8.5, 18.58256911],
    [9.5, 18.74756744],
    [10.5, 18.896042],
    [11.5, 19.03064368],
    [12.5, 19.15344332],
    [13.5, 19.26608845],
    [14.5, 19.36991062],
    [15.5, 19.46600088],
    [16.5, 19.55526398],
    [17.5, 19.63845823],
    [18.5, 19.71622527],
    [19.5, 19.78911262],
    [20.5, 19.85759111],
    [21.5, 19.92206843],
    [22.5, 19.98289982],
    [23.5, 20.04039669],
    [24.5, 20.09483318],
    [25.5, 20.14645244],
    [26.5, 20.19547032],
    [27.5, 20.24207979],
    [28.5, 20.28645383],
    [29.5, 20.32874809],
    [30.5, 20.36910308],
    [31.5, 20.4076461],
    [32.5, 20.44449276],
    [33.5, 20.4797484],
    [34.5, 20.5135092],
    [35.5, 20.54586325],
    [36, 20.56153827]

];

var hcageinf_male_97th = [
    [0, 15.29692644],
    [0.5, 15.78752209],
    [1.5, 16.51236275],
    [2.5, 17.04009099],
    [3.5, 17.45171505],
    [4.5, 17.78692672],
    [5.5, 18.06811898],
    [6.5, 18.30915881],
    [7.5, 18.51922191],
    [8.5, 18.70469394],
    [9.5, 18.87019423],
    [10.5, 19.01917133],
    [11.5, 19.15426667],
    [12.5, 19.27754729],
    [13.5, 19.39066038],
    [14.5, 19.49493913],
    [15.5, 19.59147723],
    [16.5, 19.68118252],
    [17.5, 19.76481648],
    [18.5, 19.84302372],
    [19.5, 19.91635447],
    [20.5, 19.98528194],
    [21.5, 20.05021582],
    [22.5, 20.11151303],
    [23.5, 20.16948635],
    [24.5, 20.2244108],
    [25.5, 20.27653054],
    [26.5, 20.32606185],
    [27.5, 20.37319808],
    [28.5, 20.4181124],
    [29.5, 20.46096051],
    [30.5, 20.50188288],
    [31.5, 20.54100664],
    [32.5, 20.57844717],
    [33.5, 20.61430951],
    [34.5, 20.64868954],
    [35.5, 20.68167496],
    [36, 20.69767009]

];

$(function chartSetup() {
    $('#container').highcharts({
        chart: {
            type: 'areaspline'
        },
        title: {
            text: 'Infant Head Circumference Growth Chart (Males)'
        },
        legend: {
            layout: 'horizontal',
            align: 'center',
            verticalAlign: 'bottom',
            borderWidth: 1,
            backgroundColor: '#FFFFFF',
            itemStyle: {
                cursor: 'pointer',
                color: '#274b6d',
                fontSize: '12px'
            }
        },
        plotOptions: {
            areaspline: {
                fillOpacity: 0.2
            },
            series: {
                minPointLength: 1,
                shadow: false,
                events: {
                    legendItemClick: function () {
                        if (this.name == 'Percentiles') {
                            toggleBands(chart);
                        }
                    }
                }
            }
        },
        xAxis: {
            title: {
                text: 'Age (months)'
            },
            labels: {
                rotation: -90
            }
        },
        yAxis: {
            title: {
                text: 'Head Circumference (inches)'
            },
            min: 12,
            max: 21
        },
        tooltip: {
            shared: true,
            valueSuffix: ' inches',
            valueDecimals: 2
        },
        credits: {
            enabled: false
        },
        series: [{
            name: '3rd Percentile',
            data: hcageinf_male_3rd,
            marker: {
                enabled: false
            }
        }, {
            name: '5th Percentile',
            data: hcageinf_male_5th,
            marker: {
                enabled: false
            }
        }, {
            name: '10th Percentile',
            data: hcageinf_male_10th,
            marker: {
                enabled: false
            }
        }, {
            name: '25th Percentile',
            data: hcageinf_male_25th,
            marker: {
                enabled: false
            }
        }, {
            name: '50th Percentile',
            data: hcageinf_male_50th,
            marker: {
                enabled: false
            }
        }, {
            name: '75th Percentile',
            data: hcageinf_male_75th,
            marker: {
                enabled: false
            }
        }, {
            name: '90th Percentile',
            data: hcageinf_male_90th,
            marker: {
                enabled: false
            }
        }, {
            name: '95th Percentile',
            data: hcageinf_male_95th,
            marker: {
                enabled: false
            }
        }, {
            name: '97th Percentile',
            data: hcageinf_male_97th,
            marker: {
                enabled: false
            }
        }]
    });
});

function toggleBands(chart) {
    $.each(chart.xAxis, function (index, elX) {
        $.each(elX.plotLinesAndBands, function (index, el) {
            if (el.svgElem !== undefined) {
                el.svgElem[el.visible ? 'show' : 'hide']();
                el.visible = !el.visible;
            }
        });
    });
}

$('.toggle-trigger').click(function () {
    var target = $(this).attr('data-target');

    $('#' + target).slideToggle('slow');

    if ($(this).hasClass('plus')) {
        $(this).addClass('minus').removeClass('plus');
    } else {
        $(this).addClass('plus').removeClass('minus');
    }
});